var t, a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), s = require("../../../mybehaviors/location/location"), i = getApp();

Page({
    behaviors: [ s ],
    data: {
        city: "",
        point: {
            lat: "",
            lng: ""
        },
        stores: [],
        inputs: "",
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        screenMenu: [ {
            name: "商品",
            api: "goods.goods.search-goods"
        } ],
        screenType: [ "good" ],
        screenIndex: 0,
        screenShow: !1,
        goods_template: {
            name: "02"
        },
        openTemplate: 0
    },
    onLoad: (t = e(a.default.mark(function t(e) {
        var s = this;
        return a.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                return t.next = 2, this.getScreenList(e.search_type);

              case 2:
                e.city && "1" !== e.city ? (e.city && this.setData({
                    city: e.city
                }), e.point && this.setData({
                    point: JSON.parse(e.point)
                }), this.getListData()) : this._getLocation(function() {
                    s.getListData();
                });

              case 3:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function(a) {
        return t.apply(this, arguments);
    }),
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? (console.log("111111111111111"), this.getMoreData()) : console.log("没有更多数据");
    },
    setScreenShow: function() {
        this.setData({
            screenShow: !this.data.screenShow
        });
    },
    setScreenIndex: function(t) {
        var a = t.currentTarget.dataset.index;
        a != this.data.screenIndex && (this.setData({
            screenIndex: a,
            screenShow: !1
        }), this.getListData());
    },
    gotoGoods: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    gotoSupplier: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/member/supplier/SupplierShop/SupplierShop?id=" + a
        });
    },
    onShareAppMessage: function() {
        var t = JSON.stringify(this.data.point);
        return {
            title: "",
            path: "/packageC/o2o/o2oSearchMultiple/o2oSearchMultiple?city=" + this.data.city + "&point=" + t
        };
    },
    initPage: function() {
        this.setData({
            listData: [],
            networkLoading: !1
        }), this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0;
    },
    bindInput(e){
      console.log(e,'bindInput')
      this.setData({
        inputs: e.detail.value
    })
    },
    getListData: function() {
        var t = this;
        this.initPage();
        var a = i.getNetAddresss(this.data.screenMenu[this.data.screenIndex].api), e = i.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
        a += "&lng=" + e.lng, a += "&lat=" + e.lat, a += "&city_name=" + this.data.city, 
        a += "&page=" + this.data.page;
        var s = {};
        console.log(this.data.inputs,'this.data.inputs')
        0 == this.data.screenIndex ? s["search[keyword]"] = this.data.inputs : "门店商品" == this.data.screenMenu[this.data.screenIndex].name ? s.goods_title = this.data.inputs : s.kwd = this.data.inputs, 
        i._getNetWork({
            url: a,
            data: s,
            success: function(a) {
                var e = a.data;
                if (t.setData({
                    networkLoading: !0
                }), 1 != e.result) return i.tips(e.msg);
                t.setData({
                    isLoadMore: !0,
                    total_page: e.data.last_page,
                    listData: e.data.data
                }), t.data.total_page || (t.data.total_page = 0), e.data.hasOwnProperty("store_list_style") && t.setData({
                    openTemplate: e.data.store_list_style || 0
                });
            }
        });
    },
    getMoreData: function() {
        var t = this, a = i.getNetAddresss(this.data.screenMenu[this.data.screenIndex].api), e = i.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
        if (a += "&lng=" + e.lng, a += "&lat=" + e.lat, a += "&city_name=" + this.data.city, 
        this.data.isLoadMore = !1, this.data.page >= this.data.total_page) console.log("111111111111111", this.data.page, this.data.total_page); else {
            this.data.page++;
            var s = {
                page: this.data.page
            };
            0 == this.data.screenIndex ? s["search[keyword]"] = this.data.inputs : "门店商品" == this.data.screenMenu[this.data.screenIndex].name ? s.goods_title = this.data.inputs : s.kwd = this.data.inputs, 
            i._getNetWork({
                url: a,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.data.isLoadMore = !0;
                        var s = e.data.data;
                        t.setData({
                            listData: t.data.listData.concat(s)
                        });
                    } else t.data.isLoadMore = !1, t.data.page--;
                }
            });
        }
    },
    getScreenList: function() {
        var t = this, a = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "good";
        return new Promise(function(e, s) {
            var n = i.getNetAddresss("plugins.get-enabled-plugins");
            i._getNetWork({
                url: n,
                success: function(s) {
                    var i = s.data, n = t.data.screenMenu, o = t.data.screenType;
                    1 == i.data.is_supplier && (n.push({
                        name: "供应商",
                        api: "plugin.supplier.frontend.supplier.get-supplier-list"
                    }), o.push("supplier")), 1 == i.data.is_store && (n.push({
                        name: "门店",
                        api: "plugin.store-cashier.frontend.store.store.get-store-list-to-page"
                    }), o.push("store"), n.push({
                        name: "门店商品",
                        api: "plugin.store-cashier.frontend.store.store.get-store-goods-list"
                    }), o.push("storeGood")), 1 == i.data.is_hotel && (n.push({
                        name: "酒店",
                        api: "plugin.hotel.frontend.hotel.goods.get-hotel-goods-by-title"
                    }), o.push("hotel")), t.setData({
                        screenMenu: n,
                        screenType: o
                    });
                    var r = o.indexOf(a);
                    t.data.screenMenu[r] && t.setData({
                        screenIndex: r
                    }), e();
                }
            });
        });
    }
});